package com.book.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.book.bean.Book;
import com.book.service.IBookService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller("bookSearchingAction")
@Scope("prototype")
public class BookSearchingAction extends ActionSupport {

	public String getSelectOption() {
		return selectOption;
	}

	public void setSelectOption(String selectOption) {
		this.selectOption = selectOption;
	}

	public String getWords() {
		return words;
	}

	public void setWords(String words) {
		this.words = words;
	}

	public void setBookService(IBookService bookService) {
		this.bookService = bookService;
	}

	public String searchingBook() {
		List<Book> list = null;
		switch (selectOption) {
		case "name":
			list = bookService.getBookByName(words);
			break;
		case "author":
			list = bookService.getBookByAuthor(words);
			break;
		case "publisher":
			list = bookService.getBookByPublisher(words);
			break;
		case "keywords":
			list = bookService.getBookByKeyword(words);
			break;
		}
		ActionContext.getContext().getSession().remove("allbook");
		ActionContext.getContext().getSession().put("allbook", list);
		System.out.println("option: " + selectOption + ", words: " + words);
		return SUCCESS;
	}

	private static final long serialVersionUID = -6649705181097716327L;

	@Resource
	private IBookService bookService;

	private String selectOption;
	private String words;
}
